home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / sound / rukc1d.zip / RUCK_SRC.ZIP / X01M.C < prev    next >
C/C++ Source or Header  |  1994-02-27  |  4KB  |  164 lines

  1.  
  2. #include <dos.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdarg.h>
  7.  
  8. #include "ruckmidi.h"
  9.  
  10. /*
  11. X02M.c 27-Feb-94 chh
  12. Load & Play MIDI file
  13. removed C7-specific _ all over the place
  14. */
  15.  
  16. /*
  17. The following structures are in ruckmidi.h
  18. */
  19.  
  20. #pragma pack(1)  /* ALL Ruckus data structures must be byte-aligned */
  21.  
  22. extern struct MidiDataArea pascal MIDIDATA;
  23.  
  24. struct SysInfoMidiPack SIMP;
  25. struct InitMidiPack IMP;
  26. struct XitMidiPack XMP;
  27. struct LoadMidiPack LMP;
  28. struct SetMidiPack SMP;
  29. struct SetFMProPack SFMPP;
  30. struct PlaybackMidiPack PBMP;
  31. struct OutMsgMidiPack OMMP;
  32. struct DeallocMidiPack DMP;
  33.  
  34. #pragma pack()
  35.  
  36. int rez, rez2;      /* result status codes */
  37. char nums[9] = {7}; /* number buffer for _cgets()*/
  38. char filename[81];  /* pathname to load */
  39.  
  40.  
  41. int main()
  42. {
  43.  
  44.     printf("\nX01M.C - RUCKUS-MIDI load & play of file example. [930228]\n");
  45.  
  46.     /*
  47.     Initialize RUCKMIDI and device and register ExitMidi with _atexit
  48.     */
  49.  
  50.     IMP.Func = InitMidi;
  51.     IMP.DeviceID = 1;           /* OPL-2 percussive mode */
  52.     IMP.IOport = 0x388;
  53.  
  54.     if (IMP.DeviceID == 1) {
  55.        IMP.ChMask = 0x23F;      /* mask for channels 0-5, 9 */
  56.        IMP.PercCh = 9;
  57.     }
  58.     else {
  59.        IMP.ChMask = 0x1FF;      /* mask for channels 0-8 */
  60.        IMP.PercCh = 0;
  61.     }
  62.  
  63.     IMP.Flags = 0;
  64.     rez = RUCKMIDI(&IMP);       /* Initialize */
  65.     if (rez == 0) {
  66.  
  67.         XMP.Func = AtExitMidi;
  68.         rez2 = RUCKMIDI(&XMP);
  69.         if (rez2 != 0) {
  70.             printf("AtExitMidi failed, press Enter to continue");
  71.             getchar();
  72.         }
  73.  
  74.         /*
  75.         Increase SB Pro main and FM vol volumes to max
  76.         */
  77.  
  78.         SFMPP.Func = SetAllFMSBP;
  79.         SFMPP.IOport = 0x220;       /* if there it'll respond */
  80.         SFMPP.MasterVol = 0x0F0F;   /* if not, no problem */
  81.         SFMPP.Steer = 0;
  82.         SFMPP.FMvol = 0x0F0F;
  83.         rez2 = RUCKMIDI(&SFMPP);
  84.  
  85.  
  86.         /*
  87.         Set patch map to GM or MT-32, here I'll use GM (jazz.mid is GM)
  88.         */
  89.  
  90.         SMP.Func = SetPatchMidi;
  91.         SMP.PatchMapID = 0;     /* actually, this is the GM is the default */
  92.         SMP.PatchMapPtr = NULL;
  93.         rez2 = RUCKMIDI(&SMP);
  94.  
  95.         if (SMP.PatchMapID==0)
  96.             puts("Using General MIDI map");
  97.         else
  98.             puts("Using MT-32 MIDI map");
  99.  
  100.         /*
  101.         Load a single MIDI file and play it
  102.         */
  103.  
  104.         if (rez == 0) {
  105.             /* load file and setup playback parameters */
  106.             /* rez==0 always in this example */
  107.  
  108.             printf("\nMIDI filename: ");
  109.             gets(filename);
  110.  
  111.             LMP.Func = LoadMidi;
  112.             LMP.FilenamePtr = filename;
  113.             LMP.StartPos = 0L;          /* start at first byte */
  114.             LMP.LoadSize = 0L;          /* autoload entire file */
  115.             rez = RUCKMIDI(&LMP);
  116.             if (rez == 0) {
  117.  
  118.                 printf("K bytes left: %u\n",MIDIDATA.MemDOS);
  119.                 printf("K bytes used: %u\n",MIDIDATA.MemUsed);
  120.  
  121.                 PBMP.Func = PlayMidi;
  122.                 PBMP.Mode = 1;          /* background mode a must */
  123.                 PBMP.LoadPtr = LMP.LoadPtr;
  124.                 rez = RUCKMIDI(&PBMP);
  125.  
  126.                 if (rez == 0) {
  127.                     do
  128.                        printf("\rCurrent tick: %lx",MIDIDATA.TickCount);
  129.                     while ( MIDIDATA.End == 0);
  130.  
  131.                     /*
  132.                     End play
  133.                     */
  134.  
  135.                     XMP.Func = EndMidi;
  136.                     rez2 = RUCKMIDI(&XMP);
  137.                 }
  138.                 else {
  139.                     printf("Play failed, %u\n",rez);
  140.  
  141.                 /*
  142.                 Release memory/handle used by LoadMidi
  143.                 (ExitMidi would do this, too)
  144.                 */
  145.  
  146.                 DMP.Func = DeallocMidi;
  147.         DMP.HandSeg = FP_SEG(LMP.LoadPtr);
  148.                 DMP.TypeFlag = 0;
  149.                 rez = RUCKMIDI(&DMP);  /* should error check in procode */
  150.                 }
  151.             }
  152.             else
  153.                 printf("Load failed, %u\n", rez);
  154.         }  /* rez==0 always if*/
  155.     }
  156.     else
  157.         printf("Initialization failed, %u\n", rez);
  158.  
  159. XMP.Func = ExitMidi;
  160. rez = RUCKMIDI(&XMP);
  161. return(rez);
  162.  
  163. }
  164.